﻿using System;
using System.Windows.Input;

namespace AppDesigner.Shared
{
    public class RelayCommand : ICommand
    {
        private Action _execute;
        private Func<bool> _canExecute;

        public RelayCommand(Action execute)
            : this(execute, null)
        {
        }


        public RelayCommand(Action exeucte, Func<bool> canExecute)
        {
            this._execute = exeucte;
            this._canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute();
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            _execute();
        }
    }
}
